package com.xiaobias.distributed.pan.web.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaobias.distributed.pan.db.entity.BaiduUser;
import com.xiaobias.distributed.pan.db.service.BaiduUserService;
import com.xiaobias.distributed.pan.query.UserQuery;
import com.xiaobias.distributed.pan.web.vo.UserVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户 controller
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private BaiduUserService baiduUserService;

    @PostMapping("/list")
    public IPage<UserVo> getList(@RequestBody UserQuery query) {
        return baiduUserService.page(query);
    }

    @GetMapping("/list")
    public List<UserVo> getList() {
        List<BaiduUser> users = baiduUserService.list();
        List<UserVo> userVos = new ArrayList<>();
        users.forEach(user -> {
            UserVo userVo = new UserVo();
            userVo.setId(user.getId());
            userVo.setAccount(user.getToken());
            userVo.setUsername(user.getBaiduName());
            userVos.add(userVo);
        });
        return userVos;
    }

}
